﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Models.Base;
using System.Data.SqlClient;
using System.Data;
using Dapper;
namespace WFI.DAL
{
    public class baseAccessService
    {
        public static readonly baseAccessService _baseAccessService = new baseAccessService();
        private readonly string sqlconnection = System.Configuration.ConfigurationManager.ConnectionStrings["connectDB"].ToString();
            //"Data Source=.;Initial Catalog=WFIDB;User Id=sa;Password=hi123;";
        public SqlConnection OpenConnection()
        {
            SqlConnection connection = new SqlConnection(sqlconnection);
            return connection;
        }

        /// <summary>
        /// 得到所有用户
        /// </summary>
        /// <returns>所有用户</returns>
        public  List<UserInfo> GetAllUserInfo()
        {
            using (IDbConnection conn = OpenConnection())
            {
                const string query = "select * from dbo.t_Base_UserInfo where IsDelete=1";
               return conn.Query<UserInfo>(query, null).ToList();
            }
        }

        /// <summary>
        /// 得到所有组
        /// </summary>
        /// <returns>所有组</returns>
         public  List<GroupInfo> GetAllGroupInfo()
        {
            using (IDbConnection conn = OpenConnection())
            {
                const string query = "select * from dbo.t_Base_GroupInfo where IsDelete=1";
               return conn.Query<GroupInfo>(query, null).ToList();
            }
        }

        /// <summary>
        /// 所有用户与组的关系
        /// </summary>
        /// <returns></returns>
         public List<UserLinkGroup> GetAllUserLinkGroup()
         {
             using (IDbConnection conn = OpenConnection())
             {
                 const string query = "select * from dbo.t_Base_UserLinkGroup where IsDelete=1";
                 return conn.Query<UserLinkGroup>(query, null).ToList();
             }
         }

        /// <summary>
        /// 所有功能
        /// </summary>
        /// <returns></returns>
         public List<Function> GetAllFunction()
         {
             using (IDbConnection conn = OpenConnection())
             {
                 const string query = "select * from  [dbo].[t_Base_Function] where IsDelete=1";
                 return conn.Query<Function>(query, null).ToList();
             }
         }

        /// <summary>
        /// 组对应功能
        /// </summary>
        /// <returns></returns>
         public List<GroupLinkFunction> GetAllGroupLinkFunction()
         {
             using (IDbConnection conn = OpenConnection())
             {
                 const string query = "select * from dbo.t_Base_GroupLinkFunction where IsDelete=1";
                 return conn.Query<GroupLinkFunction>(query, null).ToList();
             }
         }
      
    }

}
